package main

import (
	"fmt"
	"reflect"
)

func main() {
	var a int = 100
	testReflect(a)
}

func testReflect(a interface{}) {
	// 空接口接受
	typea := reflect.TypeOf(a)
	valuea := reflect.ValueOf(a)
	fmt.Printf("反射后的type: %T,%v; \n反射后的value: %T,%v\n", typea, typea, valuea, valuea)
	num1 := valuea.Int()
	fmt.Printf("结果转换：%T,%v\n", num1, num1)
	fmt.Println(valuea.Kind())
	switch valuea.Kind() {
	case reflect.Int, reflect.Int64, reflect.Int32:
		fmt.Println("a 的值是：", valuea.Int())
	case reflect.String:
		fmt.Println("a的值是：", valuea.String())
	case reflect.Pointer:
		fmt.Println("a 是指针，", valuea.Elem())
	default:
		fmt.Println("未找到a的类型")
	}
}
